﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using FCS.Pattern;
using FCS.Communication;


namespace FCS.Pattern
{
    public partial class MyDefaultService : ServiceBase
    {
        EventLogWriter _logger = new EventLogWriter("Default Sequence Service");
        PatternController _pattern;
        BollardController _bollard;

        public MyDefaultService()
        {
            InitializeComponent();
            _logger.WriteToLog(EventLogEntryType.Information, "Initializing service");
        }

        /// <summary>
        /// Start the controller (default: valves run)
        /// </summary>
        /// <param name="args"></param>
        protected override void OnStart(string[] args)
        {
            new Thread(() =>
            {
                _pattern = new PatternController();
                _bollard = new BollardController(true);

                _logger.WriteToLog(EventLogEntryType.Information, "OnStart service");
                _pattern.StartPattern();
                _logger.WriteToLog(EventLogEntryType.Information, "Started sequences");
                _bollard.Run();
                _logger.WriteToLog(EventLogEntryType.Information, "Started bollard service");
            }).Start();
        }


        /// <summary>
        /// Shutsdown the connection
        /// </summary>
        protected override void OnStop()
        {
            _logger.WriteToLog(EventLogEntryType.Information, "Stopping service");
            _pattern.Stop();
            _bollard.Stop();
        }



    }
}
